package com.jingan.nursinghome.regulatory.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;

import cn.android.support.v7.lib.sin.crown.base.BaseView;
import cn.android.support.v7.lib.sin.crown.utils.ProportionUtils;

/**
 * Created by 彭治铭 on 2017/10/25.
 */

public class TriangelView extends BaseView {

    public TriangelView(Context context) {
        super(context);
        init();
    }

    public TriangelView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        //super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        setMeasuredDimension(w, w);
    }

    private void init() {
    }

    String index = "1";

    public void setIndex(String index) {
        this.index = index;
        invalidate();
    }

    int w = ProportionUtils.getInstance().adapterInt(110);
    int textSize = ProportionUtils.getInstance().adapterInt(38);

    int startX=ProportionUtils.getInstance().adapterInt(0);
    int startY=startX;
    @Override
    public void draw(Canvas canvas) {
        super.draw(canvas);
        canvas.drawColor(Color.WHITE);
        Path path = new Path();
        paint.setStyle(Paint.Style.FILL_AND_STROKE);
        paint.setStrokeWidth(0);
        path.moveTo(startX, startY);
        path.lineTo(w, startY);
        path.lineTo(startX, w);
        path.close();
        paint.setColor(Color.parseColor("#4B97F0"));
        canvas.drawPath(path, paint);
        paint.setColor(Color.WHITE);
        paint.setTextSize(textSize);
        paint.setTextAlign(Paint.Align.LEFT);
        int x = w / 5;
        int y=w/6;
        if(index.length()>=2){
            x=w/20;
            y=w/10;
        }
        y = (int) (y+textSize);
        canvas.drawText(index, x, y, paint);
    }
}
